﻿package src.uipackage.ui.graphics {
	
	import flash.display.GradientType;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.filters.DropShadowFilter;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;
	
	/**
	* Just a graphic class used for OBO_Accordion
	* @author Devon O.
	*/
	public class AccordionButton extends Sprite {
		
		private var _graphic:Sprite;
		private var _overGlow:GlowFilter = new GlowFilter(0x666666, 1, 6, 6, 2, 2, true);
		private var _downShadow:DropShadowFilter = new DropShadowFilter(2, 90, 0x000000, 1, 0, 4, 1, 2, true);
		
		public function AccordionButton(topGradient:uint, bottomGradient:uint, width:Number, height:Number, useRoundedCorners:Boolean):void {
			_overGlow.color = bottomGradient;
			createGraphic(topGradient, bottomGradient, width, height, useRoundedCorners);
		}
		
		private function createGraphic(topGradient:uint, bottomGradient:uint, width:Number, height:Number, useRoundedCorners:Boolean):void {
			_graphic = new Sprite();
			var fillType:String = GradientType.LINEAR;
			var colors:Array = [topGradient, bottomGradient];
			var alphas:Array = [1, 1];
			var ratios:Array = [107, 147];
			var mat:Matrix = new Matrix();
			mat.createGradientBox(width, height, 90 * Math.PI / 180);
			var spread:String = SpreadMethod.PAD;
			_graphic.graphics.beginGradientFill(fillType, colors, alphas, ratios, mat, spread);
			if (useRoundedCorners) {
				_graphic.graphics.drawRoundRect(0, 0, width, height, 10);
			} else {
				_graphic.graphics.drawRect(0, 0, width, height);
			}
			_graphic.graphics.endFill();
			addChild(_graphic);
		}
		
		public function showOver():void {
			_graphic.filters = [_overGlow];
		}
		
		public function showDown():void {
			_graphic.filters = [_downShadow];
		}
		
		public function showUp():void {
			_graphic.filters = null;
		}
	}
}